package com.loan.system.mapper;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.loan.common.core.mapper.BaseMapperPlus;
import com.loan.common.core.page.TableDataInfo;
import com.loan.system.domain.ApplyEntity;
import org.apache.ibatis.annotations.Param;
import org.redisson.api.RMap;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @author shiguang on 2022/9/7 14:58
 */
public interface ApplyMapper extends BaseMapperPlus<ApplyMapper, ApplyEntity, ApplyEntity> {

    Page<ApplyEntity> selectPageApplyList(@Param("page") Page<ApplyEntity> page, @Param(Constants.WRAPPER) Wrapper<ApplyEntity> buildQueryWrapper);

    List<ApplyEntity> applyLogList(Long userId);

    int updateApplyOneExamineBy(@Param("oneExamineBy") Long oneExamineBy, @Param("ids") List<Long> ids);

    int updateApplyTwoExamineBy(@Param("twoExamineBy") Long twoExamineBy, @Param("ids") List<Long> ids);

    int updateApplyCutomerBy(@Param("customerBy") Long customerBy, @Param("ids") List<Long> ids);

    List<ApplyEntity> selectOverApplyList(@Param("minDay") Integer minDay, @Param("maxDay") Integer maxDay,
                                          @Param("userIds") List<Long> userIds, @Param("companyId") Long companyId);

    List<ApplyEntity> selectPageListOverRepayment(@Param("orderSn") String orderSn, @Param("userName") String userName,
                                                  @Param("userPhone") String userPhone, @Param("beginTime") String beginTime,
                                                  @Param("endTime") String endTime, @Param("userId") Long userId, @Param("companyId") Long companyId,
                                                  @Param("pageNum") Integer pageNum, @Param("pageSize") Integer pageSize);

    int selectCountOverRepayment(@Param("orderSn") String orderSn, @Param("userName") String userName,
                                 @Param("userPhone") String userPhone, @Param("beginTime") String beginTime,
                                 @Param("endTime") String endTime, @Param("userId") Long userId, @Param("companyId") Long companyId);

    /**
     * 催收订单指定分配
     *
     * @param collectionBy
     * @param list
     * @return
     */
    int updateApplyCollectionBy(@Param("collectionBy") Long collectionBy, @Param("ids") List<Long> list);

    Map<String, Object> selectMapByDateAndCompanyId(@Param("buildDate") String buildDate, @Param("companyId") Long companyId);

    Map<String, Object> selectMap1ByDateAndCompanyId(@Param("buildDate") String buildDate, @Param("companyId") Long companyId);

    List<Map<String, Object>> selectPageCapitalBack(@Param("companyId") Long companyId,@Param("beginTime") String beginTime, @Param("endTime") String endTime);

    Map<String, Object> selectMarket(@Param("beginTime") String beginTime, @Param("endTime") String endTime);

    List<Map<String, Object>> selectCompanyDataList(@Param("beginTime") String beginTime, @Param("endTime") String endTime,
                                                    @Param("companyId") Long companyId, @Param("pageNum") Integer pageNum, @Param("pageSize") Integer pageSize);

    int selectCompanyDataCount(@Param("beginTime") String beginTime, @Param("endTime") String endTime, @Param("companyId") Long companyId);

    List<Map<String, Object>> selectPayDataList(@Param("companyId") Long companyId, @Param("beginTime") String beginTime, @Param("endTime") String endTime,
                                                @Param("customerId") Long customerId, @Param("pageNum") Integer pageNum, @Param("pageSize") Integer pageSize);

    int selectPayDataCount(@Param("companyId") Long companyId, @Param("beginTime") String beginTime, @Param("endTime") String endTime, @Param("customerId") Long customerId);

    Map<String, Object> selectPayDataTotal(@Param("beginTime") String beginTime, @Param("endTime") String endTime,
                                           @Param("customerId") Long customerId, @Param("companyId") Long companyId);

    List<Map<String, Object>> selectPageExamineDataList(@Param("beginTime") String beginTime, @Param("endTime") String endTime,
                                                        @Param("oneExamineBy") Long oneExamineBy, @Param("pageNum") Integer pageNum,
                                                        @Param("pageSize") Integer pageSize);

    int selectPageExamineDataCount(String beginTime, String endTime, Long oneExamineBy);

    List<Map<String, Object>> selectIncomeExpendList(@Param("companyId") Long companyId, @Param("channel") String channel,
                                                     @Param("beginTime") String beginTime, @Param("endTime") String endTime,
                                                     @Param("pageNum") Integer pageNum, @Param("pageSize") Integer pageSize);

    int selectIncomeExpendCount(@Param("companyId") Long companyId, @Param("channel") String channel, @Param("beginTime") String beginTime, @Param("endTime") String endTime);

    List<Map<String, Object>> selectIncomeExpendTotal(@Param("companyId") Long companyId, @Param("channel") String channel, @Param("beginTime") String beginTime, @Param("endTime") String endTime);

    List<Map<String, Object>> selectOneExamineData();

    List<Map<String, Object>> selectTwoExamineData();

    List<Map<String, Object>> selectOneOverDataByData(@Param("buildDate") String buildDate, @Param("userId") Long userId);

    List<Map<String, Object>> selectTwoOverDataByData(@Param("buildDate") String buildDate, @Param("userId") Long userId);

    List<Map<String, Object>> selectLastOverDataByData(@Param("buildDate") String buildDate, @Param("userId") Long userId);

    List<ApplyEntity> selectPageList(@Param("entity") ApplyEntity entity, @Param("companyId") Long companyId,
                                     @Param("overStatus") String overStatus, @Param("isRemark") String isRemark, @Param("pageNum") Integer pageNum,
                                     @Param("pageSize") Integer pageSize);

    int selectPageCount(@Param("entity") ApplyEntity entity, @Param("companyId") Long companyId, @Param("overStatus") String overStatus, @Param("isRemark") String isRemark);

    List<ApplyEntity> selectPageWaitWithdrawallist(@Param("entity") ApplyEntity entity, @Param("companyId") Long companyId,
                                                   @Param("overStatus") String overStatus, @Param("isRemark") String isRemark,
                                                   @Param("pageNum") Integer pageNum, @Param("pageSize") Integer pageSize);

    int selectWaitWithdrawalCount(@Param("entity") ApplyEntity entity, @Param("companyId") Long companyId,
                                  @Param("overStatus") String overStatus, @Param("isRemark") String isRemark);

    List<ApplyEntity> selectFailList(@Param("userId") Long userId, @Param("companyId") Long companyId, @Param("orderSn") String orderSn,
                                     @Param("userName") String userName, @Param("userPhone") String userPhone,
                                     @Param("status") String status, @Param("overStatus") String overStatus, @Param("applyType") String applyType,
                                     @Param("createStartTime") String createStartTime, @Param("createEndTime") String createEndTime, @Param("examineStartTime") String examineStartTime,
                                     @Param("examineEndTime") String examineEndTime, @Param("pageNum") int pageNum, @Param("pageSize") int pageSize);

    int selectFailCount(@Param("userId") Long userId, @Param("companyId") Long companyId, @Param("orderSn") String orderSn,
                        @Param("userName") String userName, @Param("userPhone") String userPhone,
                        @Param("status") String status, @Param("overStatus") String overStatus, @Param("applyType") String applyType,
                        @Param("createStartTime") String createStartTime, @Param("createEndTime") String createEndTime,
                        @Param("examineStartTime") String examineStartTime, @Param("examineEndTime") String examineEndTime);

    List<ApplyEntity> selectPageListFirst(@Param("isManage") String isManage, @Param("entity") ApplyEntity entity,
                                          @Param("beginTime") Date beginTime, @Param("endTime") Date endTime,
                                          @Param("pageNum") int pageNum, @Param("pageSize") int pageSize);

    int selectCountFirst(@Param("isManage") String isManage, @Param("entity") ApplyEntity entity, @Param("beginTime") Date beginTime, @Param("endTime") Date endTime);

    List<ApplyEntity> selectPageListTwo(@Param("isManage") String isManage, @Param("entity") ApplyEntity entity,
                                        @Param("beginTime") String beginTime, @Param("endTime") String endTime,
                                        @Param("pageNum") int pageNum, @Param("pageSize") int pageSize);

    int selectCountTwo(@Param("isManage") String isManage, @Param("entity") ApplyEntity entity,
                       @Param("beginTime") String beginTime, @Param("endTime") String endTime);

    /**
     * 获取待提现列表
     *
     * @return
     */
    List<ApplyEntity> selectWithdrawalList(Integer day);

    void deleteByIds(@Param("ids") List<Long> ids);

    List<Map<String, Object>> selectListByCompanyIdAndDate(@Param("companyId") Long companyId, @Param("buildDate") String buildDate);

    int selectApplyNum(@Param("buildDate") String buildDate, @Param("channel") String channel,
                       @Param("companyId") Long companyId, @Param("beginTime") String beginTime, @Param("endTime") String endTime);

    int selectFirstOverNumByBuildDate(@Param("buildDate") String buildDate, @Param("channel") String channel,
                                      @Param("companyId") Long companyId, @Param("beginTime") String beginTime, @Param("endTime") String endTime);

    long selectRepayMoneyByDate(@Param("buildDate") String buildDate, @Param("channel") String channel,
                                @Param("companyId") Long companyId, @Param("beginTime") String beginTime, @Param("endTime") String endTime);

    Map<String, Object> selectPayMoneyAndPayNumByCompanyId(@Param("companyId") Long companyId);

    /**
     * 当天到期应还本金
     * @param collectionBy
     * @param buildDate
     * @return
     */
    long selectRepaymentByDate(@Param("collectionBy") Long collectionBy, @Param("buildDate") String buildDate);

    /**
     * 当天还款金额
     * @param collectionBy
     * @param buildDate
     * @return
     */
    long selectCallMoneyByDate(@Param("collectionBy") Long collectionBy, @Param("buildDate") String buildDate);

    /**
     * -1本金催回
     * @param collectionBy
     * @param buildDate
     * @return
     */
    long selectTomorrowAlreadyAmount(@Param("collectionBy") Long collectionBy, @Param("buildDate") String buildDate);

    long selectDayRemark(@Param("collectionBy") Long collectionBy, @Param("buildDate") String buildDate);

    /**
     * 当天新增逾期金额
     * @param collectionBy 催收人
     * @param buildDate 日期
     * @return
     */
    long selectOverMoney(@Param("collectionBy") Long collectionBy, @Param("buildDate") String buildDate);

    /**
     * 新增订单应还总金额
     * @param collectionBy 催收人
     * @param buildDate 日期
     * @return
     */
    long selectAlreadyTotalMoney(@Param("collectionBy") Long collectionBy, @Param("buildDate") String buildDate);
}
